// best_fields 数据使用disjunction_max_query.es 中的数据

// 试了下, 结果, 和 dis max query 一样, 
POST /blogs/_search
{
    "query": {
        "multi_match": {
            "type": "best_fields",
            "query": "Quick pets",
            "fields": ["title", "body"]
        }
    }
}

// 试了下, 结果, 和 dis max query 一样, 
POST /blogs/_search
{
    "query": {
        "multi_match": {
            "type": "best_fields",
            "query": "Quick pets",
            "fields": ["title", "body"],
            "tie_breaker": 0.2
        }
    }
}

// 以上 dis max query 感觉就是 multi match的best fields的alias

POST /blogs/_search
{
    "query": {
        "multi_match": {
            "type": "best_fields",
            "query": "Quick pets",
            "fields": ["title", "body"],
            "tie_breaker": 0.2,
            "minimum_should_match": "20%" // 
        }
    }
}


// most_fields
// 英文分词器会提取词干, 把running提取为run
PUT titles
{
    "mappings": {
        "properties": {
            "title": {"type": "text","analyzer": "english"}
        }
    }
}

PUT /titles/_doc/1
{ "title": "My dog barks" }
PUT /titles/_doc/2
{ "title": "I see a lot of barking dogs on the road" }

// 问题: 这个结果文档1 在前面, 但是从肉眼可见文档2 更加匹配
GET /titles/_search
{
    "query": {
        "match": {
            "title": "barking dogs"
        }
    }
}

// 解决
DELETE /titles

// 增加子字段
PUT titles
{
    "mappings": {
        "properties": {
            "title": {
                "type": "text",
                "analyzer": "english",
                "fields": {
                    "std": {"type": "text", "analyzer": "standard"}
                }
            }
        }
    }
}

PUT /titles/_doc/1
{ "title": "My dog barks" }
PUT /titles/_doc/2
{ "title": "I see a lot of barking dogs on the road" }

// 这样就解决了
GET /titles/_search
{
    "query": {
        "multi_match": {
            "type": "most_fields",
            "query": "barking dogs",
            "fields": ["title", "title.std"]

        }
    }
}

// 额外的, 还能指定字段的权重
GET /titles/_search
{
    "query": {
        "multi_match": {
            "type": "most_fields",
            "query": "barking dogs",
            "fields": ["title^2", "title.std"]

        }
    }
}

DELETE titles


// cross_fields
DELETE test_fields

PUT test_fields/_doc/1
{"first_name": "abc","last_name": "def"}

PUT test_fields/_doc/2
{"first_name": "abc","last_name": "xyz"}

GET test_fields/_search
{
    "query": {
        "multi_match": {
            "type": "cross_fields",
            "query": "abc def",
            "fields": ["first_name","last_name"]
        }
    }
}

GET test_fields/_search
{
    "query": {
        "multi_match": {
            "type": "cross_fields",
            "query": "abc xyz",
            "fields": ["first_name","last_name"]
        }
    }
}

DELETE test_fields